package com.itsm.user.service.impl;

import com.itsm.common.core.domain.R;
import com.itsm.common.user.dto.LoginDto;
import com.itsm.user.entity.JzsyRbacUser;
import com.itsm.user.mapper.JzsyRbacUserMapper;
import com.itsm.user.service.IAuthenticationService;
import com.itsm.user.service.IUserService;
import com.itsm.user.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AuthenticationServiceImpl implements IAuthenticationService {

    @Autowired
    private JzsyRbacUserMapper jzsyRbacUserMapper;

    @Autowired
    private IUserService userService;


    public String login(LoginDto loginDto){
        String account = loginDto.getAccount();
        String pwd = loginDto.getPwd();
        JzsyRbacUser u = userService.getUserByName(account);

        if(pwd.equals(u.getPassword())){
            String token = JwtUtil.getToken(u.getUserName(),u.getPassword(),true);
            return token;
        }else{
            return null;
        }

    }


//    public boolean isPhone(){
//        String el = "^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$";
//
//        return nul;
//    }






}
